<template>
    <example class="throttle-example" :template-code="templateString">
        <template #describe>
            <t :id="`${$t('其他元素、其他事件演示')}`">{{ $t('其他元素、其他事件演示') }}</t>
            <li>不单是按钮能使用防抖、节流功能，所有元素都支持的</li>
            <li>并且你可以自定义需要使用防抖、节流的事件，支持同时控制多个事件、以及时间间隔</li>
        </template>
        <sib-throttle events="click,mouseenter" :time="1000">
            <div class="example-div" @click="handleClick" @mouseenter="handleMouseenter" @mouseleave="handleMouseleave">
                <p>onClick: {{ clickTimes }}次</p>
                <p>onMouseenter: {{ mouseenterTimes }}次</p>
                <p>onMouseleave: {{ mouseleaveTimes }}次</p>
            </div>
        </sib-throttle>
    </example>
</template>

<script>
import { ref } from 'vue';

export default {
    setup() {
        const clickTimes = ref(0);
        const mouseenterTimes = ref(0);
        const mouseleaveTimes = ref(0);

        return {
            clickTimes,
            mouseenterTimes,
            mouseleaveTimes,
            handleClick() {
                clickTimes.value += 1;
            },
            handleMouseenter() {
                mouseenterTimes.value += 1;
            },
            handleMouseleave() {
                mouseleaveTimes.value += 1;
            },
            templateString: `<template>
    <div class="example-box">
        <sib-throttle events="click,mouseenter" :time="1000">
            <div class="example-div" @click="handleClick" @mouseenter="handleMouseenter" @mouseleave="handleMouseleave">
                <p>onClick: {{ clickTimes }}次</p>
                <p>onMouseenter: {{ mouseenterTimes }}次</p>
                <p>onMouseleave: {{ mouseleaveTimes }}次</p>
            </div>
        </sib-throttle>
    </div>
</template>

<script>
import { ref } from 'vue';

export default {
    setup() {
        const clickTimes = ref(0);
        const mouseenterTimes = ref(0);
        const mouseleaveTimes = ref(0);

        return {
            clickTimes,
            mouseenterTimes,
            mouseleaveTimes,
            handleClick() {
                clickTimes.value += 1;
            },
            handleMouseenter() {
                mouseenterTimes.value += 1;
            },
            handleMouseleave() {
                mouseleaveTimes.value += 1;
            },
        };
    },
};
<\/script>

<style lang="scss">
    .example-div {
        width: 150px;
        height: 150px;
        background: var(--el-primary-color-light-8);
        padding: 20px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        p {
            margin: 10px auto;
        }
    }
</style>`,
        };
    },
};
</script>

<style lang="scss">
    .throttle-example {
        .example-div {
            width: 150px;
            height: 150px;
            background: var(--el-primary-color-light-8);
            padding: 20px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            p {
                margin: 10px auto;
            }
        }
    }
</style>
